<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<!--<input type="hidden" name="rowId">-->
<div class="layuimini-container">

    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <input type="hidden" name="hiddenFieldForTable" id="hiddenFieldForTable">
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" type="button">删除</a>
        </script>

    </div>
</div>
<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
<script src="../../../api/common.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: local + 'draft/page/list',
            method: "post",
            contentType: 'application/json;charset=UTF-8',
            headers: {'Authorization': `Bearer ${ localStorage.getItem("token") }`},
            request: {
                pageName: 'pageNum',
                limitName: 'pageSize'
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                {type: 'numbers', title: '序号', width: 60, fixed: 'left' },
                {field: 'name', title: '标题', width: 220,},
                {field: 'moduleName', title: '所属栏目'},
                {field: 'createDate', title: '时间'},
                {field: 'userName', title: '作者'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            unresize: false,
            skin: 'line',
            parseData: function (res) {
                return {
                    "code": res.code === 200 ? 0 : res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.records
                };
            },
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑草稿',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    data: {id: '1234'},
                    area: ['50%', '50%'],
                    content: './edit.html?id=' + data.userId,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                $.ajax({
                    type: 'POST',
                    url: local + 'draft/delete' + data.orgId,
                    data: {},
                    dataType: "json",
                    headers: {
                        'Authorization': `Bearer ${ localStorage.getItem("token") }`,
                    },
                    contentType: 'application/json;charset=UTF-8',
                    success: function (res) {
                        if (res.code === 200) {
                            layui.table.reload('currentTableId')
                        }else{
                            layer.msg(res.msg, {icon: 0});
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, {icon: 5});
                    }
                });
            }
        });

    });
</script>

</body>
</html>
